package com.myCode.Servlet;



import com.myCode.DAO.DaoImpl.ProductDaoImpl;
import com.myCode.DAO.ProductDao;
import com.myCode.entity.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/showAll")
public class ShowAll extends HttpServlet {
    private ProductDao productDao= new ProductDaoImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过请求对象设置请求地址编码集
        req.setCharacterEncoding("utf-8");
        //通过Dao调用方法,获取处理请求的数据
        List<Product> products = productDao.selAll();
        //通过请求域对象调用方法将制定数据共享到作用域
        req.setAttribute("products",products);
        //通过req对象调用方法,将制定作用域中共享的数据转发到指定的jsp页面中
        req.getRequestDispatcher("/WEB-INF/showAll.jsp").forward(req,resp);
    }
}
